package com.example.administrator.puzzlepic;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.example.administrator.puzzlepic.com.xiaoxu.util.ScreenUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/4/5.
 */
public class GridAdapter extends ArrayAdapter {

    LayoutInflater layoutInflater;
    List<Bitmap> dataList;
    ImageView mImageView;
    Context mContext;
    View seleTypePop;
    int density;


    public GridAdapter(Context context, int resource, List objects) {

        super(context, resource, objects);
        layoutInflater = layoutInflater.from(context);
        dataList = objects;
        mContext = context;
        seleTypePop = layoutInflater.inflate(R.layout.type_popup,null);
        density = (int) ScreenUtil.getDeviceDensity(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        int density = (int) ScreenUtil.getDeviceDensity(mContext);

        if (convertView == null) {

            mImageView = new ImageView(mContext);

            mImageView.setLayoutParams(new ViewGroup.LayoutParams(80 * density, 80 * density));


        } else {

            mImageView = (ImageView) convertView;

        }

        if (position < dataList.size() - 1) {

            Bitmap bitmap = dataList.get(position);
            mImageView.setImageBitmap(bitmap);

            return mImageView;

        } else {

            View inflate = layoutInflater.inflate(R.layout.mydefined, null);

            mImageView = (ImageView) inflate.findViewById(R.id.sele_type);

            return mImageView;
        }

    }




}
